<template>
	<view class="content">
		<view class="head">
			<view class="search">
				<view class="nav-item" v-for="(i,j) in menuList" :key="j" @click="check(j)" :class="currentIndex == j?'active':''">
					<text>{{i}}</text>
				</view>
			</view>
		</view>
		<view class="section">
			<!-- 如果列表没有数据 -->
			<Null v-if="list.length == 0"></Null>
			<view class="list">
				<view class="item" @tap="toPage(i.id)" v-for="(i,j) in list" :key="j">
					<view class="msg">
						<view style="display: flex; justify-content: space-between;">
							<text >
								<text style="font-size: 28rpx; color: #333333; font-weight: 800;">合同名称：</text>
								<text style="margin-left: 10rpx;">{{i.contract_name}}</text>
							</text>
							<!-- 状态改变 -->
							<text v-if="i.status == 0" style="color: #39B54A;">
								<text class="cuIcon-title"></text>
								<text>生效中</text>
							</text>
							<text v-if="i.status == 1" style="color: #e54d42;">
								<text class="cuIcon-title"></text>
								<text>已结束</text>
							</text>
						</view>
						<view>
							<text>
								<text style="font-size: 28rpx; color: #333333; font-weight: 800;">签订地址：</text>
								<text style="margin-left: 10rpx;">{{i.address}}</text>
							</text>
						</view>
						<view>
							<text>合同编号：</text>
							<text style="background-color: #f9f3f1; color: #7a6a51; font-size: 24rpx; padding: 4rpx 8rpx;">{{i.contract_num}}</text>
						</view>
						<view class="time">
							<text></text>
							<text>
								<text>签署时间：</text>
								<text style="font-size: 24rpx; color: #AAAAAA;">{{i.create_time}}</text>
							</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// 1.tab栏,2.下拉刷新,3.为空的情况
	import api from "../../../network/index.js"
	import Null from "../../../components/common/null.vue"
	export default {
		data() {
			return {
				list:[],
				// 分页信息
				current_page: 1, // 当前页
				last_page: 0, // 最后一页
				per_page: 5, // 每页条数
				// tab切换栏
				menuList:['生效中','已结束','全部'],
				currentIndex: 0,
			}
		},
		components:{
			Null
		},
		computed:{
			status(){
				// this.projectList = []
				if(this.currentIndex == 0)return 0
				if(this.currentIndex == 1)return 1
				// if(this.currentIndex == 3)return ''
			}
		},
		methods: {
			// 跳转至合同详情
			toPage(id){
				uni.navigateTo({
					url: "./contractdetail/contractdetail?id="+id
				})
			},
			// 切换tab栏目
			check(index){
				if(index==this.currentIndex)return
				this.init()
				this.currentIndex = index
				this.getList()
			},
			// 初始化列表
			init(){
				this.list = []
				this.current_page = 1,
				this.last_page = 0
			},
			// 获取合同列表
			getList(){
				const t = this
				let data = {
					status: "=,"+this.status,
					page: this.current_page,
					list_rows: this.per_page,
					sort: "create_time:desc",
				}
				if(this.currentIndex == 2){
					delete data.status
				}
				api.request({
					url: api.CONTRACT_LIST,
					data: data
				}).then(res=>{
					// console.log(res)
					if(res.data.code == "200"){
						// 如果没数据返回空
						if(res.data.list == "暂无数据") return this.list = []
						// 如果有数据初始化页数
						this.current_page = res.data.list.current_page
						this.last_page = res.data.list.last_page
						
						this.list =this.list.concat(res.data.list.data) 
						
					} else {
						console.log(res)
						uni.showToast({
							icon: "none",
							title: "意料之外的错误~"
						})
					}
				}).catch(err=>{
					console.log(err)
					uni.showToast({
						icon: "none",
						title: "意料之外的错误~"
					})
				})
			}
		},
		onLoad() {
			this.getList()
		},
		onPullDownRefresh (){
			setTimeout(()=>{
				this.init()
				this.getList()
				uni.stopPullDownRefresh()
			},1000)
		},
		onReachBottom() {
			if(this.current_page == this.last_page){
				return
			}
			this.current_page++
			this.getList()
		},
	}
</script>

<style lang="scss" scoped>
	*{
		box-sizing: border-box;
	}
	.section{
		padding-top: 73rpx;
	}
	.list{
		// overflow: hidden;
		.item{
			display: flex;
			margin: 30rpx 20rpx;
			border-radius: 10rpx;
			background-color: #FFFFFF;
			box-shadow: 2rpx 2rpx 4rx #EEEEEE;
			border-left: 1rpx solid #ffa23e;
			box-sizing: border-box;
			.msg{
				padding: 0 20rpx;
				padding-top: 10rpx;
				flex: 1;
				view{
					height: 54rpx;
					line-height: 54rpx;
				}
				.time{
					display: flex;
					justify-content: space-between;
				}
			}
			
		}
	}
	.search{
		position: fixed;
		z-index: 100;
		left: 0;
		right: 0;
		margin: 0 0 10rpx;
		display: flex;
		justify-content: space-around;
		height: 88rpx;
		line-height: 88rpx;
		background-color: #FFFFFF;
		border-bottom: 1rpx solid #EEEEEE;
		box-shadow: 2rpx 2rpx 8rpx #EEEEEE;
		// padding-top: 15rpx;
		.nav-item{
			flex: 1;
			text-align: center;
		}
		.search-tip,.icon{
			font-size: 28rpx;
			color: #333333;
			width: 140rpx;
			text-align: center;
		}
		.input{
			flex: 1;
			// background-color: #F5F5F5;
			input{
				padding: 0 10rpx;
				font-size: 28rpx;
				text-align: center;
				height: 88rpx;
				line-height: 88rpx;
			}
		}
	}
	.active{
		background-color: #F5F5F5;
		color: #ffa23e;
		border-bottom: 1rpx solid #ffa23e;
	}
</style>

